package com.xszx.oss.controller;

import com.xszx.commonutils.R;
import com.xszx.oss.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
/**
 * @Author: 白熊
 * @Date: 2024/7/15 11:55
 */

@RestController
@RequestMapping("/eduoss/file")
//@CrossOrigin
@Api(tags = "阿里云文件管理")
public class FileUploadController {

    @Autowired
    private FileService fileService;

    @ApiOperation("删除文件")
    @DeleteMapping("url")
    public R delete(@ApiParam(name = "url", value = "路径", required = true)
                                @RequestParam("url") String url){
        fileService.delete(url);
        return R.ok().message("删除成功封面");
    }

    @ApiOperation("文件上传")
    @PostMapping("upload")
    public R upload(@ApiParam(name = "file", value = "文件", required = true)
                    @RequestParam("file") MultipartFile file,
                    @ApiParam(name = "host", value = "文件上传路径", required =  false)
                    String host){
        String uploadUrl = fileService.upload(file,host);
        return R.ok().message("文件上传成功").data("url", uploadUrl);
    }
}
